﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using transportsystem.DTO;
using UTIL;

namespace transportsystem.DAO
{
    public class ChuyenDAO
    {
        public static DataTable layDanhSachChuyen()
        {
            SqlDataAccessHelper.ConnectSQLServer();
            string procName = "sp_DanhSachChuyen";
            DataSet ds = SqlDataAccessHelper.LoadData(procName);
            if (ds != null)
                return ds.Tables[0];
            return null;
        }

        public static bool capNhatChuyen(Chuyen c1, Chuyen c2)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_CapNhatTuyen");
            cmd.Parameters.Add("@machuyen1", SqlDbType.Int).Value = c1.Machuyen;
            cmd.Parameters.Add("@giokhoihanh1", SqlDbType.DateTime).Value = c1.Giokhoihanh;
            cmd.Parameters.Add("@matuyen1", SqlDbType.Int).Value = c1.Matuyen;

            cmd.Parameters.Add("@machuyen2", SqlDbType.Int).Value = c2.Machuyen;
            cmd.Parameters.Add("@giokhoihanh2", SqlDbType.DateTime).Value = c2.Giokhoihanh;
            cmd.Parameters.Add("@matuyen2", SqlDbType.Int).Value = c2.Matuyen;

            return SqlDataAccessHelper.ExecCmd(cmd);
        }

        public static bool xoaChuyen(Chuyen c)
        {
            SqlCommand cmd = SqlDataAccessHelper.CreateCommand("sp_XoaChuyen");
            cmd.Parameters.Add("@machuyen", SqlDbType.Int).Value = c.Machuyen;
            return SqlDataAccessHelper.ExecCmd(cmd);
        }
    }
}
